package com.auto.learning.view;

import com.auto.learning.R;
import com.auto.learning.tools.CommonMethod;
import com.auto.learning.tools.PopWindowUtils;
import com.auto.learning.tools.PopWindowUtils.PopUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

/**
 * 购买书单成功提示单
 * */
public class PuPSdPaySucceedDialog implements PopUtil {
	private PopupWindow popupWindow;
	private Context context;
	private TextView tv_message;
	private ImageView im_bookimage;
	private TextView tv_succeed;
	private DisplayImageOptions options;

	public PuPSdPaySucceedDialog(Context context) {
		this.context = context;
		View view = LayoutInflater.from(context).inflate(R.layout.pupsdpaysuess, null);
		initDisplayImageOptions();
		im_bookimage = (ImageView) view.findViewById(R.id.im_bookimage);
		tv_message = (TextView) view.findViewById(R.id.tv_message);
		tv_succeed = (TextView) view.findViewById(R.id.tv_succeed);
		tv_succeed.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dissmiss();
			}
		});
		LinearLayout popup_shadow = (LinearLayout) view
				.findViewById(R.id.popup_shadow);
		LinearLayout lin_layout=(LinearLayout) view.findViewById(R.id.lin_layout);
		lin_layout.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				
				return true;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}
		});
		popup_shadow.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				Log.i("mengdd", "onTouch : ");
				dissmiss();
				return false;
				// 这里如果返回true的话，touch事件将被拦截
				// 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
			}
		});
		popupWindow = PopWindowUtils.getPopupWindow(popupWindow, view);

	}

	public void setImageUrl(String url) {
		ImageLoader.getInstance().displayImage(url, im_bookimage, options);
	}

	public void initDisplayImageOptions() {
		options = new DisplayImageOptions.Builder()
				.showImageOnLoading(R.drawable.book)
				.showImageForEmptyUri(R.drawable.book)
				.showImageOnFail(R.drawable.book).cacheInMemory(true)
				.cacheOnDisk(true).considerExifParams(true)
				.bitmapConfig(Bitmap.Config.RGB_565).build();
	}

	public void setMessageText(String str) {
		tv_message.setText(str);

	}

	@Override
	public void dissmiss() {
		// TODO Auto-generated method stub
		popupWindow.dismiss();
	}

	@Override
	public void show(View dropview) {
		// TODO Auto-generated method stub
		int statusBarHeight = CommonMethod.getStatusHeight((Activity) context);
		popupWindow.showAtLocation(dropview, Gravity.CENTER, 0, statusBarHeight);
	}
	public void test(){
//		PuPSdPaySucceedDialog dialog=new PuPSdPaySucceedDialog(BookListActivity.this);
//		String str=String.format(getResources().getString(R.string.test_secceed_message),bookListModel.getName());
//		dialog.setMessageText(str);
//		dialog.setImageUrl(bookListModel.getFaceImg());
//		dialog.show(activity_base_back);
	}
}
